import StatusCodes from 'http-status-codes'
import express, { Request, Response, Router } from 'express'
import { ParamMissingError } from '@shared/errors'
import axios from 'axios'
import { send } from 'process'

// Constants
const router: Router = express.Router()
const { CREATED, OK } = StatusCodes

// Paths
export const p = {
  get: '/',
  // add: '/add',
  // update: '/update',
  // delete: '/delete/:id',
} as const

/**
 * 获取数据.
 */
router.get(p.get, async (req: Request, res: Response) => {
  // 异步
  // const users = await userService.getAll();
  const result = await axios.post(
    'https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=localCityNCOVDataList,diseaseh5Shelf'
  )
  res.json(result.data)
  // return res.status(OK).json({users});
})

// /**
//  * Add one user.
//  */
// router.post(p.add, async (req: Request, res: Response) => {
//     const { user } = req.body;
//     // Check param
//     if (!user) {
//         throw new ParamMissingError();
//     }
//     // Fetch data
//     await userService.addOne(user);
//     return res.status(CREATED).end();
// });

// /**
//  * Update one user.
//  */
// router.put(p.update, async (req: Request, res: Response) => {
//     const { user } = req.body;
//     // Check param
//     if (!user) {
//         throw new ParamMissingError();
//     }
//     // Fetch data
//     await userService.updateOne(user);
//     return res.status(OK).end();
// });

// /**
//  * Delete one user.
//  */
// router.delete(p.delete, async (req: Request, res: Response) => {
//     const { id } = req.params;
//     // Check param
//     if (!id) {
//         throw new ParamMissingError();
//     }
//     // Fetch data
//     await userService.delete(Number(id));
//     return res.status(OK).end();
// });

// Export default
export default router
